package com.servlet;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Random;

import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.model.Orderitem;
import com.model.Orders;
import com.model.Shopcart;
import com.model.User;
import com.service.OrderItemService;
import com.util.Conversion;
import com.util.JdbcUtil;
import com.util.PageUtil;

/**
 * Servlet implementation class OrderServlet
 */
@WebServlet("/item")
public class OrderItemServlet extends BaseServlet  {
	JdbcUtil jdbc=new JdbcUtil();
	
	OrderItemService itemService=new OrderItemService();
	private void toOrderItem(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Integer cp = Integer.parseInt(request.getParameter("cp")==null?"1":request.getParameter("cp"));
		Integer pagesize=5;
		String oid =request.getParameter("oid");
	//	System.out.println("odi为："+oid);
		Orderitem item = new Orderitem();
		item.setOid(oid);
		List<Orderitem> orderitems = null;
		orderitems=itemService.queryItem_show(item, cp, pagesize);
		int count=itemService.count_user(item);
		
		String pageTool = PageUtil.getPageTool(request, count, cp, pagesize);
		request.setAttribute("pageTool",pageTool);
		request.setAttribute("orderitems", orderitems);
		//System.out.println(orderitems);
		request.getRequestDispatcher("orderitem.jsp").forward(request, response);
	}

	/*private void add(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Orderitem item = new Orderitem();
		String[] pids=request.getParameterValues("pid");
		String[] pnames=request.getParameterValues("pname");
		String[] pimages=request.getParameterValues("pimage");
		String[] pprices=request.getParameterValues("pprice");
		String[] weights=request.getParameterValues("weight");
		String[] tprices=request.getParameterValues("tprice");
		String oid =request.getParameter("oid");
		String uid=request.getParameter("uid");
		String eid =null;
		eid =request.getParameter("eid");
		for(int i =0;i<tprices.length;i++){
			System.out.println(tprices[i]);
		}
		for(int i =0;i<tprices.length;i++){
			//设置子订单号
			String ooid =i+"";
			System.out.println(ooid+" "+weights[i]);
			String sql ="insert into orderitem values(?,?,?,?,?,?,?,?,?,?)";
			try {
				jdbc.updatePreparedStatement(sql,ooid,oid,uid,
						pids[i],null,pnames[i],pimages[i],pprices[i],weights[i],tprices[i]);
				jdbc.close();
				System.out.println("Item执行完成");
			
				request.getRequestDispatcher("cart?action=delAllByUid").forward(request, response);
				return;
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
	}*/
}
